package org.ycsoft.PathComputation;

import java.util.*;

/**
 * The central repository where all stops are stored. It exposes all needed functionnality to add
 * and remove stops.
 * @author allad
 *
 */
public class StopDB { 
    
    private Map<String,Stop> stopsCentral = new HashMap<String,Stop>();
    
    /**
     * Add a stop with the given name to the DB.
     * If a stop with the same name already exists, it is just returned. Otherwise, a new stop
     * object is created.
     * @param stopName the station name
     * @return the Stop object with the given stop name
     */
    public Stop addStop(String stopName){
        if(stopsCentral.containsKey(stopName)){
            return stopsCentral.get(stopName);
        }
        else{
            Stop newStop = new Stop(stopName);
            stopsCentral.put(stopName,newStop);
            return newStop;
        }
    }
    
    /**
     * 
     * @param stopName the name of the stop to look for
     * @return true if a stop with the given name already exists. false otherwise
     */
    public boolean contains(String stopName){
        return stopsCentral.containsKey(stopName);
    }
    
    /**
     * 
     * @param stop the stop to look for
     * @return true if the stop already exists. false otherwise
     */
    public boolean contains(Stop stop){
        return stopsCentral.containsValue(stop);
    }
    
    /**
     * @param stopName the name of stop to fetch
     * @return the stop with the given name 
     */
    public Stop getStop(String stopName){
        return stopsCentral.get(stopName);
    }
    
    /**
     * @return A collection of all the stops in the map
     */
    public Collection<Stop> getStopsSet(){
    	Collection<Stop> retVal = stopsCentral.values();
    	
    	return retVal;
    }
    
    /**
     * @return the number of stops currently stored
     */
    public int size(){
        return stopsCentral.size();
    }
}
